﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RenAi.Medical.Model;
using System.Data;
namespace RenAi.Medical.DAL
{
   public class UsersDAL
    {
        /// <summary>
        /// 登陆（判断用户明密码是否正确）
        /// </summary>
        /// <param name="u"></param>
        /// <returns></returns>
        public int Login(string name, string pwd)
        {
            string str ="select COUNT(*) from Users where Users_Name='"+name+"' and Users_pwd='"+pwd+"'";
            return Convert.ToInt32(DBhelper.Scalar(str));
        }
        /// <summary>
        /// 获取所有用户信息
        /// </summary>
        /// <param name="u"></param>
        /// <returns></returns>
        public List<Users> Users()
        {
            string str = "select Users_Id,Users_Name,REPLICATE('*',LEN(Users_Pwd))Users_Pwd,Role_Name from Users join Role on Role.Role_Id=Users.Role_Id";
            DataTable dt = DBhelper.GetTable(str);
            List<Users> list = new List<Users>();
            foreach (DataRow item in dt.Rows)
            {
                Users u = new Users();
                u.Users_Id = Convert.ToInt32(item["Users_Id"]);
                u.Users_Name = item["Users_Name"].ToString();
                u.Users_pwd = item["Users_pwd"].ToString();
                u.Role_Name = item["Role_Name"].ToString();
                list.Add(u);
            }
            return list;
        }
    }
}
